package cn.tedu.apiday04;

import java.io.*;

public class SeriablizableAction {//测试序列化，反序列化

    public static void main(String[] args) throws IOException, ClassNotFoundException {
       //seria();//序列化
        deseria();//反序列化
    }

    private static void deseria() throws IOException, ClassNotFoundException {//反序列化，把已经序列化好的文件，恢复到 java程序中
        //创建对象
        ObjectInputStream out = new ObjectInputStream(new FileInputStream("E:\\360downloads\\520.txt"));

        //完成反序列化
        Object o = out.readObject();
        System.out.println(o);
        //释放资源
        out.close();
    }

    private static void seria() throws IOException {//序列化   把程序中准备好的Java对象，永久的写出在磁盘里   out
        //创建对象
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("E:\\360downloads\\520.txt"));
        //完成序列化
        Student s = new Student("孙",19);
        //java.io.NotSerializableException
        out.writeObject(s);
        //释放资源
        out.close();
    }
}
